package org.soft.carbon_neutral.controller;

import com.alibaba.fastjson.JSON;
import org.soft.carbon_neutral.entity.Manager;
import org.soft.carbon_neutral.service.impl.ManagerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manage")
@CrossOrigin
public class ManagerController {

    @Autowired
    private ManagerServiceImpl managerService;

    @PostMapping("/login/{username}/{password}")
    public String login(@PathVariable("username") String username,@PathVariable("password") String password) {
        return JSON.toJSONString(managerService.login(username, password));
    }

    @GetMapping("/selectAll")
    public String selectAll() {return JSON.toJSONString(managerService.selectAllManager());}

    @GetMapping("selectOneById/{id}")
    public String selectOneById(@PathVariable("id") Integer id) {
        return JSON.toJSONString(managerService.selectOneById(id));
    }

    @PostMapping("/updateManager")
    public String updateManager(@RequestBody Manager manager) {
        return JSON.toJSONString(managerService.updateMangerById(manager));
    }

    @PutMapping("/deleteManager/{id}")
    public String deleteManager(@PathVariable("id") Integer id) {
        return JSON.toJSONString(managerService.removeManager(id));
    }

    @PostMapping("/addManager")
    public String addManager(@RequestBody Manager manager) {
        return JSON.toJSONString(managerService.register(manager));
    }
}
